feat(auth): include user.complementary in /token response#3739
Conversation
Generalizes the downstream patch applied by trawl_node: the `token` handler now projects `complementary` alongside the other user fields so per-user UI prefs / extras rehydrate across full-page refresh without local override. Adds regression test (auth.token.controller.unit.tests.js) to lock the field in the projection going forward. Closes #3738
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe PR adds the ChangesUser complementary field in token response
Estimated code review effort🎯 2 (Simple) | ⏱️ ~18 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds the complementary field to the user projection returned by the /api/auth/token handler so that per-user UI prefs / extras stored on user.complementary survive a full-page refresh, matching the existing User model, schema, and account controller projection. A new ESM unit test file locks in this projection key to prevent future regressions.
Changes:
- Add
complementary: req.user.complementaryto the token handler's user projection inmodules/auth/controllers/auth.controller.js. - Add new unit tests
modules/auth/tests/auth.token.controller.unit.tests.jsassertingcomplementaryis present in the/tokenresponse (both populated and undefined cases).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| modules/auth/controllers/auth.controller.js | Adds complementary to the projected user object in the token handler. |
| modules/auth/tests/auth.token.controller.unit.tests.js | New ESM unit tests guarding the complementary field in the /token user projection. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3739 +/- ##
=======================================
Coverage 89.92% 89.92%
=======================================
Files 148 148
Lines 4865 4865
Branches 1533 1533
=======================================
Hits 4375 4375
Misses 385 385
Partials 105 105
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary
complementary: req.user.complementaryto the user-projection object in thetokenhandler (modules/auth/controllers/auth.controller.js), closing a gap vs the existing account controller projection and User model/schema which already expose this field.modules/auth/tests/auth.token.controller.unit.tests.js) to lock the field in the projection going forward.Why
Every devkit downstream that stores per-user UI preferences or extra data in
user.complementaryneeds this field to survive a full-page refresh — the client calls/api/auth/tokenon reload to rehydrate session state. Withoutcomplementaryin the token response, per-user prefs silently reset on reload.The
complementaryfield already exists in:modules/users/models/users.model.mongoose.js(model)modules/users/models/users.schema.js(Zod schema)modules/users/config/users.development.config.js(read/update/updateAdmin projections)modules/users/controllers/users.account.controller.js(account endpoint projection)The token handler was the only place missing it, forcing downstreams to patch locally.
Test plan
npm run lint— ESLint cleannpm run test:unit— 111 suites, 1582 tests pass (including 2 new regression tests)Closes #3738
Summary by CodeRabbit
New Features
Tests